package com.liancheng.smarthome.module;

import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.support.v7.widget.LinearLayoutManager;

import com.liancheng.smarthome.R;
import com.liancheng.smarthome.base.BaseActivity;
import com.liancheng.smarthome.base.TitleEventListener;
import com.liancheng.smarthome.bean.ListBeans;
import com.liancheng.smarthome.bean.LoginParamsBean;
import com.liancheng.smarthome.databinding.ForListView;
import com.liancheng.smarthome.bean.PageTitleBean;
import com.liancheng.smarthome.utils.logs.LogTag;
import com.liancheng.smarthome.base.TitleEventModule;

import java.util.ArrayList;
import java.util.List;

/**
 * 进行列表组件组装
 */
public class ForListActivity extends BaseActivity<ForListVM,ForListView> implements
        TitleEventListener.OnClickLeftImg {

    private PageTitleBean pageTitleBean;

    @java.lang.Override
    public int getLayoutId() {
        return R.layout.activity_for_list;
    }

    @java.lang.Override
    public void afterCreate() {
        pageTitleBean = new PageTitleBean(R.mipmap.icon_back_left_white, "测试列表" );
        contentView.setPageTitle(pageTitleBean);
        //没有将触发对象放入到 contentView 导致点击事件触发失败
        contentView.setTitleEvent(new TitleEventModule(this));

        contentView.setUrl("https://upload.jianshu.io/users/upload_avatars/15363225/63d9ccb4-c2b7-4623-9359-07e23753dfa8.jpg?imageMogr2/auto-orient/strip|imageView2/1/w/80/h/80/format/webp");

        contentView.setListNet(VM.getNetListener());

        contentView.setUserParams(new LoginParamsBean("15010619576","123456abc"));
// 这个是超级封装的适配器 R.layout.item_my_weather 是适配器的布局文件
        ForListAdapter tAdapter = new ForListAdapter (this, R.layout.item_list_item);
        LinearLayoutManager layoutManagerT = new LinearLayoutManager(this);
        contentView.recycleList.setLayoutManager(layoutManagerT); // 设置recyclerview布局方式
        contentView.recycleList.setAdapter(tAdapter); //给recyclerview 添加适配器

        List<ListBeans> beans = new ArrayList<>();
        for (int i = 0; i < 20; i++) {
            ListBeans listBeans = new ListBeans();
            listBeans.buildData("前名字"+i,"后名字"+i,i);
            beans.add(listBeans);
        }
        LogTag.d("长度："+beans.size());
        tAdapter.addRecordList(beans);
    }

    @java.lang.Override
    public void clickLeftImg() {
        this.finish();
    }
}
